package cn.xspace.wnx.view.chat.chatrow;

import android.content.Context;
import android.text.TextUtils;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.xspace.android.xafcommon.util.Constants;
import com.xspace.android.xafcommon.util.LogUtil;

import cn.xspace.wnx.R;
import cn.xspace.chatui.bean.MsgRecordEntity;

/**
 * Created by liuchen on 2016/11/22.
 */

public class ChatRowLink extends EaseChatRowText {
    private TextView linkTextView;

    public ChatRowLink(Context context, MsgRecordEntity message, int position, BaseAdapter adapter) {
        super(context, message, position, adapter);
    }

    @Override
    protected void onInflateView() {
        inflater.inflate(!isMySend() ?
                R.layout.chat_received_link : R.layout.chat_row_sent_link, this);
    }

    @Override
    protected void onFindViewById() {
        super.onFindViewById();
        LogUtil.d("onFindViewById");
        linkTextView = (TextView) findViewById(R.id.tx_link);
        LogUtil.d("linkTextView == null " + (linkTextView == null));
    }

    @Override
    public void onSetUpView() {
        LogUtil.d("onSetUpView");
//        super.onSetUpView();
        if (!TextUtils.isEmpty(message.msg_content)) {
            if (message.msg_content.contains(Constants.CHAR_SPECIAL)) {
                LogUtil.d(message.msg_content );
                String[] args = message.msg_content.split(Constants.CHAR_SPECIAL);
                LogUtil.d( args[0]);
                LogUtil.d( args[1]);
                if (args.length == 2) {
                    if(linkTextView!=null){
                        linkTextView.setText(args[1]);
                    }else {
                        LogUtil.d("linkTextView == null");
                    }
                    contentView.setText(args[0]);
                } else {
                    linkTextView.setText(R.string.no_link);
                }
            }
        }
        handleTextMessage();
    }

    @Override
    protected void handleTextMessage() {
        super.handleTextMessage();
    }

    @Override
    protected void onUpdateView() {
        super.onUpdateView();
    }

    @Override
    protected void onBubbleClick() {
        super.onBubbleClick();
    }

    @Override
    protected void buildSendMap() {
        super.buildSendMap();
    }
}
